# 设置编译选项（宏定义）
add_compile_definitions(
    _GNU_SOURCE
    DEBUG_EXPORT_ERROR_STRINGS=1
    FRAMEWORK_STYLE_INCLUDES=0
    TARGET_HAS_NATIVE_INT128=0
    TARGET_NEEDS_NATURAL_ALIGNMENT=1
    AES_UTILS_USE_GLADMAN_AES=1
    USE_VIA_ACE_IF_PRESENT=0
    TARGET_HAS_MD5_UTILS=1
    TARGET_HAS_SHA_UTILS=1
    TARGET_NO_OPENSSL=1
    TARGET_HAS_LIBTOMMATH=1
    AES_UTILS_HAS_GLADMAN_GCM=0
    MFI_AUTH_DEVICE_PATH=\"/dev/i2c-1\"
    MFI_AUTH_DEVICE_ADDRESS=0x10
    __STDC_LIMIT_MACROS=1
    CFL_BINARY_PLISTS=1
    CFLITE_ENABLED=1
    DEBUG_CF_OBJECTS_ENABLED=1
    DEBUG=1
    AIRPLAY_SCREEN=1
)

# 设置头文件搜索路径
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/Curve25519
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/Ed25519
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/GladmanAES
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/LibTomMath
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/Small25519
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/SRP
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/Support
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

# 源文件列表
set(SOURCE_FILES
    AccessorySDK/Support/AESUtils.c
    AccessorySDK/Support/AsyncConnection.c
    AccessorySDK/Support/AtomicUtils.c
    AccessorySDK/Support/BonjourBrowser.c
    AccessorySDK/Support/CFCompat.c
    AccessorySDK/Support/CFLite.c
    AccessorySDK/Support/CFLiteBinaryPlist.c
    AccessorySDK/Support/CFLitePreferencesFile.c
    AccessorySDK/Support/CFLiteRunLoopSelect.c
    AccessorySDK/Support/CFUtils.c
    AccessorySDK/Support/ChaCha20Poly1305.c
    AccessorySDK/Support/CommandLineUtils.c
    AccessorySDK/Support/DataBufferUtils.c
    AccessorySDK/Support/DebugIPCUtils.c
    AccessorySDK/Support/DebugServices.c
    AccessorySDK/Support/DispatchLite.c
    AccessorySDK/Support/HTTPClient.c
    AccessorySDK/Support/HTTPMessage.c
    AccessorySDK/Support/HTTPServer.c
    AccessorySDK/Support/HTTPUtils.c
    AccessorySDK/Support/KeychainLiteFile.c
    AccessorySDK/Support/KeychainUtils.c
    AccessorySDK/Support/LogUtils.c
    AccessorySDK/Support/MathUtils.c
    AccessorySDK/Support/MFiSAP.c
    AccessorySDK/Support/MFiServerPlatformLinux.c
    AccessorySDK/Support/MiscUtils.c
    AccessorySDK/Support/NetTransportChaCha20Poly1305.c
    AccessorySDK/Support/NetUtils.c
    AccessorySDK/Support/NetworkChangeListener.c
    AccessorySDK/Support/PairingUtils.c
    AccessorySDK/Support/PrintFUtils.c
    AccessorySDK/Support/RandomNumberUtils.c
    AccessorySDK/Support/SHAUtils.c
    AccessorySDK/Support/SRPUtils.c
    AccessorySDK/Support/StringUtils.c
    AccessorySDK/Support/ThreadUtils.c
    AccessorySDK/Support/TickUtils.c
    AccessorySDK/Support/TimeUtils.c
    AccessorySDK/Support/TLVUtils.c
    AccessorySDK/Support/URLUtils.c
    AccessorySDK/Support/utfconv.c
    AccessorySDK/Support/UUIDUtils.c

    AccessorySDK/External/Curve25519/curve25519-donna.c

    Sources/airplayutil.c

    AccessorySDK/External/Small25519/Small25519.c

    AccessorySDK/External/Ed25519/ed25519.c

    AccessorySDK/External/GladmanAES/aes_modes.c
    AccessorySDK/External/GladmanAES/aescrypt.c
    AccessorySDK/External/GladmanAES/aeskey.c
    AccessorySDK/External/GladmanAES/aestab.c

    AccessorySDK/External/LibTomMath/bn_fast_mp_invmod.c
    AccessorySDK/External/LibTomMath/bn_fast_mp_montgomery_reduce.c
    AccessorySDK/External/LibTomMath/bn_fast_s_mp_mul_digs.c
    AccessorySDK/External/LibTomMath/bn_fast_s_mp_mul_high_digs.c
    AccessorySDK/External/LibTomMath/bn_fast_s_mp_sqr.c
    AccessorySDK/External/LibTomMath/bn_mp_2expt.c
    AccessorySDK/External/LibTomMath/bn_mp_abs.c
    AccessorySDK/External/LibTomMath/bn_mp_add_d.c
    AccessorySDK/External/LibTomMath/bn_mp_add.c
    AccessorySDK/External/LibTomMath/bn_mp_clamp.c
    AccessorySDK/External/LibTomMath/bn_mp_clear_multi.c
    AccessorySDK/External/LibTomMath/bn_mp_clear.c
    AccessorySDK/External/LibTomMath/bn_mp_cmp_d.c
    AccessorySDK/External/LibTomMath/bn_mp_cmp_mag.c
    AccessorySDK/External/LibTomMath/bn_mp_cmp.c
    AccessorySDK/External/LibTomMath/bn_mp_cnt_lsb.c
    AccessorySDK/External/LibTomMath/bn_mp_copy.c
    AccessorySDK/External/LibTomMath/bn_mp_count_bits.c
    AccessorySDK/External/LibTomMath/bn_mp_div_2.c
    AccessorySDK/External/LibTomMath/bn_mp_div_2d.c
    AccessorySDK/External/LibTomMath/bn_mp_div_3.c
    AccessorySDK/External/LibTomMath/bn_mp_div_d.c
    AccessorySDK/External/LibTomMath/bn_mp_div.c
    AccessorySDK/External/LibTomMath/bn_mp_dr_is_modulus.c
    AccessorySDK/External/LibTomMath/bn_mp_dr_reduce.c
    AccessorySDK/External/LibTomMath/bn_mp_dr_setup.c
    AccessorySDK/External/LibTomMath/bn_mp_exch.c
    AccessorySDK/External/LibTomMath/bn_mp_exptmod_fast.c
    AccessorySDK/External/LibTomMath/bn_mp_exptmod.c
    AccessorySDK/External/LibTomMath/bn_mp_grow.c
    AccessorySDK/External/LibTomMath/bn_mp_init_copy.c
    AccessorySDK/External/LibTomMath/bn_mp_init_multi.c
    AccessorySDK/External/LibTomMath/bn_mp_init_size.c
    AccessorySDK/External/LibTomMath/bn_mp_init.c
    AccessorySDK/External/LibTomMath/bn_mp_invmod_slow.c
    AccessorySDK/External/LibTomMath/bn_mp_invmod.c
    AccessorySDK/External/LibTomMath/bn_mp_karatsuba_mul.c
    AccessorySDK/External/LibTomMath/bn_mp_karatsuba_sqr.c
    AccessorySDK/External/LibTomMath/bn_mp_lshd.c
    AccessorySDK/External/LibTomMath/bn_mp_mod_2d.c
    AccessorySDK/External/LibTomMath/bn_mp_mod_d.c
    AccessorySDK/External/LibTomMath/bn_mp_mod.c
    AccessorySDK/External/LibTomMath/bn_mp_montgomery_calc_normalization.c
    AccessorySDK/External/LibTomMath/bn_mp_montgomery_reduce.c
    AccessorySDK/External/LibTomMath/bn_mp_montgomery_setup.c
    AccessorySDK/External/LibTomMath/bn_mp_mul_2.c
    AccessorySDK/External/LibTomMath/bn_mp_mul_2d.c
    AccessorySDK/External/LibTomMath/bn_mp_mul_d.c
    AccessorySDK/External/LibTomMath/bn_mp_mul.c
    AccessorySDK/External/LibTomMath/bn_mp_mulmod.c
    AccessorySDK/External/LibTomMath/bn_mp_prime_is_divisible.c
    AccessorySDK/External/LibTomMath/bn_mp_prime_is_prime.c
    AccessorySDK/External/LibTomMath/bn_mp_prime_miller_rabin.c
    AccessorySDK/External/LibTomMath/bn_mp_prime_rabin_miller_trials.c
    AccessorySDK/External/LibTomMath/bn_mp_read_unsigned_bin.c
    AccessorySDK/External/LibTomMath/bn_mp_reduce_2k_l.c
    AccessorySDK/External/LibTomMath/bn_mp_reduce_2k_setup_l.c
    AccessorySDK/External/LibTomMath/bn_mp_reduce_2k_setup.c
    AccessorySDK/External/LibTomMath/bn_mp_reduce_2k.c
    AccessorySDK/External/LibTomMath/bn_mp_reduce_is_2k_l.c
    AccessorySDK/External/LibTomMath/bn_mp_reduce_is_2k.c
    AccessorySDK/External/LibTomMath/bn_mp_reduce_setup.c
    AccessorySDK/External/LibTomMath/bn_mp_reduce.c
    AccessorySDK/External/LibTomMath/bn_mp_rshd.c
    AccessorySDK/External/LibTomMath/bn_mp_set_int.c
    AccessorySDK/External/LibTomMath/bn_mp_set.c
    AccessorySDK/External/LibTomMath/bn_mp_sqr.c
    AccessorySDK/External/LibTomMath/bn_mp_sqrmod.c
    AccessorySDK/External/LibTomMath/bn_mp_sub_d.c
    AccessorySDK/External/LibTomMath/bn_mp_sub.c
    AccessorySDK/External/LibTomMath/bn_mp_to_unsigned_bin.c
    AccessorySDK/External/LibTomMath/bn_mp_toom_mul.c
    AccessorySDK/External/LibTomMath/bn_mp_toom_sqr.c
    AccessorySDK/External/LibTomMath/bn_mp_unsigned_bin_size.c
    AccessorySDK/External/LibTomMath/bn_mp_zero.c
    AccessorySDK/External/LibTomMath/bn_prime_tab.c
    AccessorySDK/External/LibTomMath/bn_reverse.c
    AccessorySDK/External/LibTomMath/bn_s_mp_add.c
    AccessorySDK/External/LibTomMath/bn_s_mp_exptmod.c
    AccessorySDK/External/LibTomMath/bn_s_mp_mul_digs.c
    AccessorySDK/External/LibTomMath/bn_s_mp_mul_high_digs.c
    AccessorySDK/External/LibTomMath/bn_s_mp_sqr.c
    AccessorySDK/External/LibTomMath/bn_s_mp_sub.c
    AccessorySDK/External/LibTomMath/bncore.c

    AccessorySDK/External/SRP/cstr.c
    AccessorySDK/External/SRP/srp.c
    AccessorySDK/External/SRP/srp6_client.c
    AccessorySDK/External/SRP/srp6_server.c
    AccessorySDK/External/SRP/t_math.c
)

# 添加共享库
add_library(SharkCoreUtils SHARED ${SOURCE_FILES})



# 设置链接器标志（-Wl,--unresolved-symbols=ignore-all）
set_target_properties(SharkCoreUtils PROPERTIES
    LINK_FLAGS "-Wl,--unresolved-symbols=ignore-all"
)


# 1. 设置包含目录
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/Curve25519
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/Ed25519
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/GladmanAES
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/LibTomMath
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/SRP
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/Support
    ${CMAKE_CURRENT_SOURCE_DIR}/Platform
    ${CMAKE_CURRENT_SOURCE_DIR}/Sources
    ${CMAKE_CURRENT_SOURCE_DIR}/Support
    ${CMAKE_CURRENT_SOURCE_DIR}/Examples
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${CMAKE_CURRENT_SOURCE_DIR}/../iap2CPP/include
    ${CMAKE_CURRENT_SOURCE_DIR}/../iap2CPP/include/util
)

# 2. 设置源文件列表
set(SOURCE_FILES
    Sources/AirPlayReceiverPOSIX.c
    Sources/AirPlayReceiverServer.c
    Sources/AirPlayReceiverSession.c
    Sources/AirPlayReceiverSessionAudio.c
    Sources/AirPlayReceiverSessionScreen.c
    Sources/AirPlayUtils.c
    Sources/AirTunesClock.c
    Sources/APReceiverStatsCollector.c
    Sources/APSRTPJitterBuffer.c
    Sources/APSRTPPacketHandler.c
    Sources/CarPlayControlClient.c
    Sources/SimpleQueue.c

    Platform/AudioUtilsStub.c

    Platform/ScreenUtilsStub.c

    Examples/AudioConverter_FDKAAC_OPUS.c
    Examples/genericStds.cpp

    Platform/HIDKnob.c
    Platform/HIDMediaButtons.c
    Platform/HIDProximity.c
    Platform/HIDTelephony.c
    Platform/HIDTouchpad.c
    Platform/HIDTouchScreen.c
)

# 3. 添加库目标，生成共享库
add_library(SharkCarPlay SHARED ${SOURCE_FILES})

# 4. 编译选项（相当于LOCAL_CFLAGS）
target_compile_options(SharkCarPlay PRIVATE
    -D_GNU_SOURCE
    -DDEBUG_EXPORT_ERROR_STRINGS=1
    -DFRAMEWORK_STYLE_INCLUDES=0
    -DTARGET_HAS_NATIVE_INT128=0
    -DTARGET_NEEDS_NATURAL_ALIGNMENT=1
    -DAES_UTILS_USE_GLADMAN_AES=1
    -DUSE_VIA_ACE_IF_PRESENT=0
    -DTARGET_HAS_MD5_UTILS=1
    -DTARGET_HAS_SHA_UTILS=1
    -DTARGET_NO_OPENSSL=1
    -DTARGET_HAS_LIBTOMMATH=1
    -DAES_UTILS_HAS_GLADMAN_GCM=0
    -DMFI_AUTH_DEVICE_PATH=\"/dev/i2c-1\"
    -DMFI_AUTH_DEVICE_ADDRESS=0x10
    -D__STDC_LIMIT_MACROS=1
    -DCFL_BINARY_PLISTS=1
    -DCFLITE_ENABLED=1
    -DDEBUG_CF_OBJECTS_ENABLED=1
    -DDEBUG=1
    -DAIRPLAY_SCREEN=1
)

# 5. 链接库，替代 LOCAL_SHARED_LIBRARIES
target_link_libraries(SharkCarPlay
    PRIVATE
    SharkCoreUtils
    iap2CPP
    AAC
    ${CMAKE_SOURCE_DIR}/lib/armeabi-v7a/libmdnssd-shark.so
)

# message(STATUS "TinkerCMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}")


# 6. 链接器选项 (LOCAL_LDFLAGS)
target_link_options(SharkCarPlay PRIVATE -Wl,--unresolved-symbols=ignore-all)


#另一个库 libAppStub

# 添加头文件搜索路径
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/Platform
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/Support/
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/Curve25519
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/Ed25519
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/GladmanAES
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/LibTomMath
    ${CMAKE_CURRENT_SOURCE_DIR}/AccessorySDK/External/SRP
    ${CMAKE_CURRENT_SOURCE_DIR}/Sources
    ${CMAKE_CURRENT_SOURCE_DIR}/Support
    ${CMAKE_CURRENT_SOURCE_DIR}/Examples
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${CMAKE_CURRENT_SOURCE_DIR}/../iap2CPP/include/util
    ${CMAKE_CURRENT_SOURCE_DIR}/../iap2CPP/include
)

# 添加源文件
add_library(AppStub SHARED
    Examples/AppleCarPlay_AppStub.c
    Examples/iAP2_AppStub.c
)


# 链接依赖的共享库
target_link_libraries(AppStub
    iap2CPP
    SharkCoreUtils
    SharkCarPlay
)





